/*
 * THE SOURCE CODES OF THE SOFTWARE ARE VALUABLE ASSETS OF FIDUS TECHNOLOGIES LTD.
 * YOU AGREE TO KEEP ALL SOURCE CODES OF THE SOFTWARE IN CONFIDENCE. YOU MAY NOT TRANSFER
 * OR ASSIGN THE SOFTWARE OR YOUR RIGHTS UNDER THIS AGREEMENT.
 * LIMITED WARRANTY
 * THE SOFTWARE AND ACCOMPANYING WRITTEN MATERIALS (INCLUDING INSTRUCTIONS FOR USE) ARE PROVIDED "AS IS"
 * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. YOU ASSUME THE ENTIRE
 * RISK AS TO THE RESULTS AND PERFORMANCE OF THE SOFTWARE.
 * FIDUS TECHNOLOGIES DOES NOT WARRANT THAT THE SOFTWARE WILL MEET ALL YOUR REQUIREMENTS, THAT OPERATIONS
 * OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL SOFTWARE ERRORS WILL BE CORRECTED.
 * FIDUS TECHNOLOGIES-SOFTWARE SOLUTIONS IS NOT RESPONSIBLE FOR PROBLEMS CAUSED BY CHANGES IN THE
 * OPERATING CHARACTERISTICS OF COMPUTER HARDWARE OR COMPUTER OPERATING SYSTEMS WHICH ARE MADE AFTER
 * WHICH ARE MADE AFTER THE RELEASE OF THE SOFTWARE NOR FOR PROBLEMS IN THE INTERACTION OF THE SOFTWARE
 * WITH NON-FIDUS TECHNOLOGIES APPLICATION.WILL HAVE NO RESPONSIBILITY TO REPLACE OR REFUND THE LICENSE FEES
 * FOR MEDIA DAMAGED BY ACCIDENT, ABUSE OR MISAPPLICATION. THIS SOFTWARE IS INTENDED FOR COMMERCIAL,
 * INSTITUTIONAL, AND INDUSTRIAL USERS. THE ABOVE WARRANTIES ARE EXCLUSIVE AND IN LIEU OF ALL OTHER WARRANTIES,
 * WHETHER EXPRESSED OR IMPLIED, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE AND NON-INFRINGEMENT. NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY FIDUS TECHNOLOGIES,
 * ITS EMPLOYEES, DISTRIBUTORS, DEALERS OR AGENTS SHALL INCREASE THE SCOPE OF THE ABOVE WARRANTIES OR
 * CREATE ANY NEW WARRANTIES. NEITHER FIDUS TECHNOLOGIES NOR ANYONE ELSE WHO HAS BEEN INVOLVED IN THE
 * CREATION, PRODUCTION OR DELIVERY OF THE SOFTWARE SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL
 * OR INCIDENTAL DAMAGES (INCLUDING DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS LOSSES, BUSINESS
 * INTERRUPTION, LOSS OF DATA, AND THE LIKE) ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE,
 * OR ANY OTHER CLAIM BY ANY PARTY EVEN IF FIDUS TECHNOLOGIES HAS BEEN ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGES. IN THE EVENT FIDUS TECHNOLOGIES IS LIABLE FOR ANY DAMAGES, FIDUS TECHNOLOGIES' LIABILITY
 * FOR DAMAGES SHALL BE LIMITED TO THE AMOUNT PAID FOR THE SOFTWARE UNDER THE TERMS AND CONDITIONS OF THIS
 * AGREEMENT.
 * http://www.fidustechnologies.com
 * Copyright(C) 2010 FIDUS TECHNOLOGIES-Software Solutions(R)
 * All rights reserved.
 */

package com.fidus.inventory.beans.purchase;

import com.fidus.inventory.beans.items.ItemStock;
import com.fidus.inventory.beans.transport.TransportDetails;
import com.fidus.inventory.beans.vendor.VendorDetails;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Mahesh Kedari<mahesh.kedari@fidustechnologies.com>
 */
@Entity
@Table(name = "Item_Purchase")
@NamedQueries({
    @NamedQuery(name = "ItemPurchase.findAll", query = "SELECT i FROM ItemPurchase i"),
    @NamedQuery(name = "ItemPurchase.findByPurchaseID", query = "SELECT i FROM ItemPurchase i WHERE i.purchaseID = :purchaseID"),
    @NamedQuery(name = "ItemPurchase.findByPurchaseDate", query = "SELECT i FROM ItemPurchase i WHERE i.purchaseDate = :purchaseDate"),
    @NamedQuery(name = "ItemPurchase.findByTotalAmount", query = "SELECT i FROM ItemPurchase i WHERE i.totalAmount = :totalAmount"),
    @NamedQuery(name = "ItemPurchase.findByPaidAmount", query = "SELECT i FROM ItemPurchase i WHERE i.paidAmount = :paidAmount"),
    @NamedQuery(name = "ItemPurchase.findByPercentDiscount", query = "SELECT i FROM ItemPurchase i WHERE i.percentDiscount = :percentDiscount"),
    @NamedQuery(name = "ItemPurchase.findByTax1Amount", query = "SELECT i FROM ItemPurchase i WHERE i.tax1Amount = :tax1Amount"),
    @NamedQuery(name = "ItemPurchase.findByTax2Amount", query = "SELECT i FROM ItemPurchase i WHERE i.tax2Amount = :tax2Amount")})
public class ItemPurchase implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "Purchase_ID", nullable = false)
    private Long purchaseID;
    @Basic(optional = false)
    @Column(name = "Purchase_Date", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date purchaseDate;
    @Basic(optional = false)
    @Column(name = "Total_Amount", nullable = false)
    private float totalAmount;
    @Basic(optional = false)
    @Column(name = "Paid_Amount", nullable = false)
    private float paidAmount;
    @Column(name = "Percent_Discount", precision = 4, scale = 2)
    private Float percentDiscount;
    @Column(name = "Tax1_Amount", precision = 5, scale = 2)
    private Float tax1Amount;
    @Column(name = "Tax2_Amount", precision = 5, scale = 2)
    private Float tax2Amount;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "itemPurchase")
    private Collection<ItemPurchaseDetails> itemPurchaseDetailsCollection;
    @JoinColumn(name = "Vendor_ID", referencedColumnName = "Vendor_ID", nullable = false)
    @ManyToOne(optional = false)
    private VendorDetails vendorDetails;
    @JoinColumn(name = "Transport_ID", referencedColumnName = "Transport_ID")
    @ManyToOne
    private TransportDetails transportDetails;
    @OneToMany(mappedBy = "itemPurchase")
    private Collection<ItemStock> itemStockCollection;

    public ItemPurchase() {
    }

    public ItemPurchase(Long purchaseID) {
        this.purchaseID = purchaseID;
    }

    public ItemPurchase(Long purchaseID, Date purchaseDate, float totalAmount, float paidAmount) {
        this.purchaseID = purchaseID;
        this.purchaseDate = purchaseDate;
        this.totalAmount = totalAmount;
        this.paidAmount = paidAmount;
    }

    public Long getPurchaseID() {
        return purchaseID;
    }

    public void setPurchaseID(Long purchaseID) {
        this.purchaseID = purchaseID;
    }

    public Date getPurchaseDate() {
        return purchaseDate;
    }

    public void setPurchaseDate(Date purchaseDate) {
        this.purchaseDate = purchaseDate;
    }

    public float getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(float totalAmount) {
        this.totalAmount = totalAmount;
    }

    public float getPaidAmount() {
        return paidAmount;
    }

    public void setPaidAmount(float paidAmount) {
        this.paidAmount = paidAmount;
    }

    public Float getPercentDiscount() {
        return percentDiscount;
    }

    public void setPercentDiscount(Float percentDiscount) {
        this.percentDiscount = percentDiscount;
    }

    public Float getTax1Amount() {
        return tax1Amount;
    }

    public void setTax1Amount(Float tax1Amount) {
        this.tax1Amount = tax1Amount;
    }

    public Float getTax2Amount() {
        return tax2Amount;
    }

    public void setTax2Amount(Float tax2Amount) {
        this.tax2Amount = tax2Amount;
    }

    public Collection<ItemPurchaseDetails> getItemPurchaseDetailsCollection() {
        return itemPurchaseDetailsCollection;
    }

    public void setItemPurchaseDetailsCollection(Collection<ItemPurchaseDetails> itemPurchaseDetailsCollection) {
        this.itemPurchaseDetailsCollection = itemPurchaseDetailsCollection;
    }

    public VendorDetails getVendorDetails() {
        return vendorDetails;
    }

    public void setVendorDetails(VendorDetails vendorDetails) {
        this.vendorDetails = vendorDetails;
    }

    public TransportDetails getTransportDetails() {
        return transportDetails;
    }

    public void setTransportDetails(TransportDetails transportDetails) {
        this.transportDetails = transportDetails;
    }

    public Collection<ItemStock> getItemStockCollection() {
        return itemStockCollection;
    }

    public void setItemStockCollection(Collection<ItemStock> itemStockCollection) {
        this.itemStockCollection = itemStockCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (purchaseID != null ? purchaseID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ItemPurchase)) {
            return false;
        }
        ItemPurchase other = (ItemPurchase) object;
        if ((this.purchaseID == null && other.purchaseID != null) || (this.purchaseID != null && !this.purchaseID.equals(other.purchaseID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.fidus.inventory.beans.company.ItemPurchase[purchaseID=" + purchaseID + "]";
    }

}
